package com.ydgg.ltar.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ydgg.ltar.mapper.ArBuildingListMapper;
import com.ydgg.ltar.mapper.ArBuildingMapper;
import com.ydgg.ltar.model.ArBuilding;
import com.ydgg.ltar.model.ArBuildingList;
import com.ydgg.ltar.util.Result;


@Service
public class ArBuildingListService {

	@Autowired
	private ArBuildingListMapper arBuildingListMapper;
	@Autowired
	private ArBuildingMapper arBuildingMapper;
	
	
	/**
	 * 条件查询
	 * 作者： 张叶
	 * 创建时间：2018年12月22日  下午2:37:14
	 */
	public List<ArBuildingList> selectByWhere(String where){
		List<ArBuildingList> list = arBuildingListMapper.selectByWhere(where);
		return list;
	}
	
	
	/**
	 * 添加
	 * 作者： 张叶
	 * 创建时间：2018年12月22日  下午2:37:08
	 */
	public Result insert(ArBuildingList abl){
		Result result = new Result();
		abl.setCreatedAt(new Date());
		abl.setStatus("on");
		if(abl.getArBuildingId() != null && !"".equals(abl.getArBuildingId())){
			ArBuilding ab = arBuildingMapper.selectByPrimaryKey(abl.getArBuildingId());
			if(ab != null){
				int i = arBuildingListMapper.insert(abl);
				if(i > 0){
					result.code = 0;
					result.message = "添加成功";
				}else{
					result.code = 1;
					result.message = "系统错误，添加失败";
				}
			}else{
				result.code = 2;
				result.message = "参数异常，刷新重试";
			}	
		}else{
			result.code = 2;
			result.message = "参数异常，刷新重试";
		}	
		return result;
	}
	
	
	/**
	 * 删除
	 * 作者： 张叶
	 * 创建时间：2018年12月22日  下午2:37:25
	 */
	public Result deleted(Long id){
		Result result = new Result();
		ArBuildingList abl = arBuildingListMapper.selectByPrimaryKey(id);
		if(abl != null){
			abl.setStatus("deleted");
			int i = arBuildingListMapper.updateByPrimaryKey(abl);
			if(i > 0){
				result.code = 0;
				result.message = "删除成功";
			}else{
				result.code = 1;
				result.message = "系统错误，删除失败";
			}
		}else{
			result.code = 0;
			result.message = "删除成功";
		}
		return result;
	}
}
